﻿using NewsMine.Utilities;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Security.Cryptography;
using System.Text;

namespace NewsMine.Utilities.Tests
{
    
    
    /// <summary>
    ///This is a test class for FuzzyStringTest and is intended
    ///to contain all FuzzyStringTest Unit Tests
    ///</summary>
    [TestClass()]
    public class FuzzyStringTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for GetSimilarIndex
        ///</summary>
        [TestMethod()]
        public void GetSimilarIndexTest()
        {
            string inputA = "YS Jagan Meets YCP Leaders at his House Live Visuals";
            string inputB = "YS Jagan Meet Union Leaders Gather at Lotus Pond Live Update ";
            double actual;
            actual = FuzzyString.GetSimilarIndex(inputA, inputA + " Gather at Lotus");

            var cosineSimilarity = CosineSimilarity.FindSimilarity(inputA, inputA + " Gather at Lotus");

            SimilarityTool simTool = new SimilarityTool();

            var simResult = simTool.CompareStrings(inputA, inputA + "kdkfsjdlsd alkdsfjasd " );
        }

        [TestMethod()]
        public void TestHashing()
        {
            string tempStr = "slfjalkdfj adsflajdslf adflkajsd flajsdflk afljasdlfjalsdjf laksdjflkadjf lasflasldfjalksdjflaksdj faldfladjflkasdjflaksdjfladsjflasdjf ";

            string hash = CreateMD5Hash(tempStr);
            hash = CreateMD5Hash(tempStr + "dkfkd");
            hash = CreateMD5Hash(tempStr + "j");
        }

        public string CreateMD5Hash(string input)
        {
            // Use input string to calculate MD5 hash
            MD5 md5 = System.Security.Cryptography.MD5.Create();
            byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(input);
            byte[] hashBytes = md5.ComputeHash(inputBytes);

            // Convert the byte array to hexadecimal string
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < hashBytes.Length; i++)
            {
                sb.Append(hashBytes[i].ToString("X2"));
                // To force the hex string to lower-case letters instead of
                // upper-case, use he following line instead:
                // sb.Append(hashBytes[i].ToString("x2")); 
            }
            return sb.ToString();
        }


    }
}
